package com.myblog.services.impl;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.myblog.Utils.RedisCache;
import com.myblog.Utils.SecurityUtils;
import com.myblog.domain.GlobalResponse;
import com.myblog.domain.contants.GlobalConstants;
import com.myblog.domain.entity.User;
import com.myblog.domain.entity.enums.GlobalResponseEnum;
import com.myblog.mapper.UserMapper;
import com.myblog.services.AdminLogoutService;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
@Service
public class AdminLogoutServiceImpl extends ServiceImpl<UserMapper, User> implements AdminLogoutService  {

    @Resource
    RedisCache redisCache;
    @Override
    public GlobalResponse logout() {
        //获取登录用户的id,并在redis中删除该id对应的token即可
        Long id=SecurityUtils.getUserId();
        redisCache.deleteObject("adminLogin:"+id);
        return GlobalResponse.ok(GlobalResponseEnum.SUCCESS_LOGOUT);
    }
}
